package ce.com.cenewbluesdk.entity.k6;

import ce.com.cenewbluesdk.CEBC;
import ce.com.cenewbluesdk.entity.BaseData;
import ce.com.cenewbluesdk.entity.CEDevData;
import ce.com.cenewbluesdk.uitl.Lg;

/**
 * Created by Administrator on 2016/12/21 0021.
 */

public class K6_MusicInfo extends BaseData {
    private int musicstatus;//app告知手机当前播放状态，可为播放或暂停
    private String musicName;	//当前音乐的名字
    private String artistName;//当前歌手名字
    private String albumName;//当前专辑的名字


    public K6_MusicInfo(int musicstatus, String musicName, String artistName, String albumName) {
        this.musicstatus = musicstatus;
        this.musicName = musicName;
        this.artistName = artistName;
        this.albumName = albumName;
    }



    public int getMusicstatus() {
        return musicstatus;
    }

    public void setMusicstatus(int musicstatus) {
        this.musicstatus = musicstatus;
    }

    public String getMusicName() {
        return musicName;
    }

    public void setMusicName(String musicName) {
        this.musicName = musicName;
    }

    public String getArtistName() {
        return artistName;
    }

    public void setArtistName(String artistName) {
        this.artistName = artistName;
    }

    public String getAlbumName() {
        return albumName;
    }

    public void setAlbumName(String albumName) {
        this.albumName = albumName;
    }
    
    
    @Override
    public CEDevData toCEDevData() {
        byte[] payload = getBytes();
        CEDevData ceDevData=new CEDevData();
        ceDevData.setCmd(CEBC.K6.CMD_TYPE_SEND);
        ceDevData.setDataType(CEBC.K6.DATA_TYPE_MUSIC_CONTENT);
        ceDevData.setData(payload);
        ceDevData.setItemL(payload.length);
        ceDevData.setItemNumber(1);
        return ceDevData;
    }

    public byte[] getBytes() {
        byte[] bytes=new byte[76];
        bytes[0]= (byte) musicstatus;
        //  音乐名字

        if(musicName!=null){
            while (musicName.getBytes().length>24){
                musicName=musicName.substring(0,musicName.length()-1);
            }
            bytes[1]= (byte) musicName.getBytes().length;
            System.arraycopy(musicName.getBytes(),0,bytes,2,bytes[1]);
            Lg.e("musicName="+CEBC.byte2hex(musicName.getBytes()));
        }


        //  音乐名字
        if(artistName!=null){
            while (artistName.getBytes().length>24){
                artistName=artistName.substring(0,artistName.length()-1);
            }
            bytes[26]= (byte) artistName.getBytes().length;
            System.arraycopy(artistName.getBytes(),0,bytes,27,bytes[26]);
            Lg.e("artistName="+CEBC.byte2hex(artistName.getBytes()));
        }

        if(albumName!=null){
            while (albumName.getBytes().length>24){
                albumName=albumName.substring(0,albumName.length()-1);
            }
            bytes[51]= (byte) albumName.getBytes().length;
            System.arraycopy(albumName.getBytes(),0,bytes,52,bytes[51]);
            Lg.e("albumName="+CEBC.byte2hex(albumName.getBytes()));
        }

        Lg.e(CEBC.byte2hex(bytes));
        return bytes;
    }
}
